﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ObjectMerger.Extensions;
using ObjectMerger.SystemTests.TestClasses;

namespace ObjectMerger.SystemTests
{
    /// <summary>
    /// Mergetests.
    /// </summary>
    [TestClass]
    public class MergeTests
    {
        [TestMethod]
        public void MergePerson()
        {
            var source = new Person
                                {
                                    FirstName = "Voornaam",
                                    SurName = "van",
                                    LastName = "Achternaam",
                                    BirthDate = new DateTime(1990, 10, 11),
                                    Address = new Address
                                                {
                                                    StreetName = "Straat",
                                                    HouseNumber = 1,
                                                    HouseNumberAdd = "Plaats"
                                                }
                                };
            var target = new Person
            {
                FirstName = "NieuweVoornaam",
                SurName = "de",
                LastName = "NieuweAchternaam",
                BirthDate = new DateTime(1981, 10, 11),
                Address = new Address
                {
                    StreetName = "NieuweStraat",
                    HouseNumber = 2,
                    HouseNumberAdd = "NieuwePlaats"
                }
            };

            source = source.MergeWith(target);

            Assert.IsTrue(source.LastName == "NieuweAchternaam", "Achternaam klopt niet");
            Assert.IsTrue(source.Address.StreetName == "NieuweStraat", "Straat klopt niet");
        }

        [TestMethod]
        public void MergePersonList()
        {
            var sourceList = new List<Person>
                                     {
                                         new Person
                                             {
                                                 FirstName = "Voornaam",
                                                 SurName = "van",
                                                 LastName = "Achternaam",
                                                 BirthDate = new DateTime(1990, 10, 11),
                                                 Address = new Address
                                                             {
                                                                 StreetName = "Straat",
                                                                 HouseNumber = 1,
                                                                 City = "Plaats"
                                                             }
                                             }
                                     };
            var targetList = new List<Person>
                                      {
                                          new Person
                                              {
                                                  FirstName = "NieuweVoornaam",
                                                  SurName = "de",
                                                  LastName = "NieuweAchternaam",
                                                  BirthDate = new DateTime(1981, 10, 11),
                                                  Address = new Address
                                                              {
                                                                  StreetName = "NieuweStraat",
                                                                  HouseNumber = 2,
                                                                  City = "NieuwePlaats"
                                                              }
                                              }
                                      };

            sourceList = sourceList.MergeWith(targetList);

            Assert.IsTrue(sourceList[0].LastName == "NieuweAchternaam", "Achternaam klopt niet");
            Assert.IsTrue(sourceList[0].Address.StreetName == "NieuweStraat", "Straat klopt niet");
        }
    }
}
